package com.fresh.fresh.controller;

import com.fresh.fresh.dao.Commodity;
import com.fresh.fresh.service.CommodityService;
import com.fresh.fresh.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *商品列表
 */
@RestController
@RequestMapping("/commodity")
@Api(tags = "商品接口")
public class CommodityController {

    @Autowired
    CommodityService commodityService;

    @GetMapping("/allCommodity")
    @ApiOperation("获取全部商品接口")
    public Result<?> getCommodity() {
        List<Commodity> data = commodityService.list();
        return Result.success(data);
    }

    @GetMapping ("/search")
    @ApiOperation("搜索商品接口")
    public Result<?> search(@RequestParam("name") String name){
        List<Commodity> searchList = commodityService.search(name);
        return Result.success(searchList);
    }


}
